#coding=utf-8
#将HTMLTestRunner放入Lib目录 是测试框架提供的HTML报告
from selenium import webdriver
from HTMLTestRunner import HTMLTestRunner
import unittest
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
import time

class Ishop(unittest.TestCase):
    def setUp(self):
        self.driver=webdriver.Firefox()
        self.driver.implicitly_wait(5)
        self.url="http://localhost:8888/iwebshop"
    def test_login(self):
        driver=self.driver
        driver.get(self.url)
        driver.maximize_window()
        driver.find_element_by_link_text(u'登录').click()
        driver.implicitly_wait(5)
        driver.find_element_by_name('login_info').send_keys('zhangsan')
        driver.find_element_by_name('password').send_keys('123456')
        driver.find_element_by_class_name('submit_login').submit()
    def tearDown(self):
        self.driver.quit()
if __name__=="__main__":
    testunit=unittest.TestSuite()
    testunit.addTest(Ishop("test_login"))
    #获取当前时间
    now=time.strftime("%Y-%m-%d %H_%M_%S")
    #二进制方式写入,没有该文件,新建,不要带中文路径哦!!!
    fo=open('./result.html'+now+'wb')
    runner=HTMLTestRunner(stream=fo,
                          title='iwebshop登录测试报告',
                          description='用例执行情况:')
    runner.run(testunit)
    fo.close()
